﻿namespace Pap.Web.Modules.Membership.ViewModel
{
    using System;
    using System.Collections.Generic;
    using Microsoft.Practices.ServiceLocation;
    using Pap.Data;
    using Pap.Data.Abstraction.Utils;
    using Pap.Web.Utils;

    /// <summary>
    /// 
    /// </summary>
    public class RolesListViewModel : IViewModel
    {
        /// <summary>
        /// 
        /// </summary>
        IMembershipRepository _MembershipRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="RolesListViewModel"/> class.
        /// </summary>
        /// <param name="MembershipInstance">The membership instance.</param>
        public RolesListViewModel(IMembershipRepository MembershipInstance)
        {
            _MembershipRepository = MembershipInstance;
        }

        /// <summary>
        /// Finds the specified role name.
        /// </summary>
        /// <param name="RoleName">Name of the role.</param>
        /// <returns></returns>
        public IEnumerable<IRole> Find(string RoleName)
        {
            return _MembershipRepository.FindRoles(R => R.RoleName.Contains(RoleName));
        }

        /// <summary>
        /// Deletes all.
        /// </summary>
        /// <param name="RolesIDs">The roles I ds.</param>
        public void DeleteAll(List<Guid> RolesIDs)
        {
            using (IUnitOfWork transaction = ServiceLocator.Current.GetInstance<IUnitOfWork>())
            {
                _MembershipRepository.DeleteRoles(r => RolesIDs.Contains(r.RoleID));
                transaction.Commit();
            }
        }

    }
}
